// __PUBLIC__/js/page/admin/user/shiftusergroup
require(['../../common'], function() {
  require(['user.shiftusergroup'])
})

define('user.shiftusergroup', [
  'jquery',
  'page/grid'
], function($, Grid) {
  'use strict';

  var $table = $('.table')
  var mygrid = new Grid($table)
  mygrid.init()

  $(document)
    .on('click', '#J_shift', function(e) {
      e.preventDefault()
      shiftData(getSelected())
    })

  function getSelected() {
    var selected = mygrid.getSelected()
    if (!selected.count) {
      alert(lang.pleaseSelectAData)
      return
    }
    return selected
  }

  function shiftData(selected) {
    var uid = $('#uids').val()
    $.post(APP + '?app=admin&m=User&a=shiftUserGroups', {
      uid: uid,
      gid: selected.id.join()
    })
      .done(function(res) {
        if (res == '1') {
          location.href = APP + '?app=admin&m=User&a=user'
        } else {
          $('#ispan').html('{$Think.lang.transferFails}').css('color', 'red')
        }
      })
  }

})
